//
//  SignUpViewController.m
//  TipsProject
//
//  Created by Suny on 15/5/8.
//  Copyright (c) 2015年 Suny. All rights reserved.
//

#import "SignUpViewController.h"
#import "UserService.h"
#import "IZValueSelectorView.h"
@interface SignUpViewController ()
@property (nonatomic,strong)UserService *service;
@property (nonatomic,strong)UserInfo *userInfo;
@property (nonatomic,weak) UIButton *backBtn;



@end

@implementation SignUpViewController

- (UserService *)service
{
	if (!_service)
    {
		_service = [UserService serviceWithDefaultBaseUrlString];
	}
	return _service;
}

- (void)viewDidLoad 
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.
	[self.view setBackgroundColor:HEXCOLOR(0x59B1DA)];
	self.navigationController.navigationBarHidden = YES;
	self.userInfo = [[UserInfo alloc] init];

	
	UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
	[button setImage:[UIImage imageNamed:@"navigationbar_back_icon"] forState:UIControlStateNormal];
	[button setTitle:@"返回" forState:UIControlStateNormal];
	
	[button addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
	
	button.frame = CGRectMake(20,self.view.height - 100, 100, 44);
	[self.view addSubview:button];
	
}

- (void)didReceiveMemoryWarning 
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)handleClickSexBtn:(UIButton *)handleClickSexBtn
{
	handleClickSexBtn.selected = !handleClickSexBtn.selected;
	UIButton *male = (UIButton *)[self.view viewWithTag:Tag_SexMaleButton];
	UIButton *female = (UIButton *)[self.view viewWithTag:Tag_SexFemalnButton];
	UIButton *otherButton = ([male isEqual:handleClickSexBtn]?female:male);
	otherButton.selected = NO;
	self.userInfo.sex = handleClickSexBtn.titleLabel.text;
}

- (void)registToServer
{
	[super registToServer];
	
	UserInfo *user = self.userInfo;
	user.loginName = [self textFieldWithTag:Tag_EmailTextField].text;
	user.password = [self textFieldWithTag:Tag_TempPasswordTextField].text;
	user.nickName = [self textFieldWithTag:Tag_NikeNameTextField].text;
//	user.firstName = [self textFieldWithTag:Tag_FirstNameTextField].text;
//	user.secondName = [self textFieldWithTag:Tag_SecondTextField].text;
	user.headImage = self.headerImageView.image;
	user.aboutMyself = @"";
	WEAKSELF
	[self.service registerUser:user
			   WithFinishBlock:^(BaseResponse *response) {
				   if (response.success)
				   {
					   [weakSelf registSucceed:response];
				   }
				   else
				   {
					   [weakSelf registFaild:response];
				   }
			   }];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

- (void)selector:(IZValueSelectorView *)valueSelector didSelectRowAtIndex:(NSInteger)index 
{
	self.userInfo.age = [NSString stringWithFormat:@"%ld",(long)index];
}

@end
